package br.com.duosoftware.orcamento.entidades;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author Renato
 *
 */
@Entity
@Table(name = "alienas", uniqueConstraints = {@UniqueConstraint(columnNames = {"codigo","rubrica_id"})})
public class Alinea implements Serializable, BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    //
    @Column(length = 2)
    private String codigo;
    //
    @Column(length = 80)
    private String descricao;
    //
    @ManyToOne
    @JoinColumn(name = "rubrica_id", referencedColumnName = "id")
    private Rubrica rubrica;

    @Override
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public Rubrica getRubrica() {
        return rubrica;
    }

    public void setRubrica(Rubrica rubrica) {
        this.rubrica = rubrica;
    }
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Alinea other = (Alinea) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return  rubrica.getEspecie().getOrigem().getCategoriaEconomicaDeReceita().getCodigo() + "." 
              + rubrica.getEspecie().getOrigem().getCodigo() + "."
              + rubrica.getEspecie().getCodigo() + "."
              + rubrica.getCodigo() + "."
              + codigo + " - " + descricao;
    }
    
}
